<?php
namespace Home\Controller;
use Think\Controller;

class IndexController extends Controller {
	
	function index() {
		$this->loadData ();
		writeLog ( 'visit', 'visit' );
		$this->redirect ( "/Home/Index/toStart" );
	}
	
	function toStart() {
		session ( 'html_userInfo', "<li class='li_no_user'><a onClick=toLogin('show')>登录</a>&nbsp;&nbsp;&nbsp;
					<a onClick=toSignup('show') class='li_username'>注册</a></li>" );
		
		if (session ( "nwb_islogin" ) != null) {
			
			$userMenu = "<li class='li_user_title' onClick='userMenu()'>
                        	<img src='".C('web_root')."Public/Image/moren_touxiang.jpg' align='absmiddle'>".
                        	substr ( session ( 'nwb_email' ), 0, strrpos ( session ( 'nwb_email' ), '@' ) )."
                        </li>
                    	<li class='li_user_ops' onclick=rePassword('show')><img align='absmiddle' src='".C('web_root')."Public/Image/user_repwd.png'>更改密码</li>
                    	<li class='li_user_ops'><img align='absmiddle' src='".C('web_root')."Public/Image/user_logout.png'><a href='../User/toLogout'>退出登录</a></li>";
			
			session ( 'html_userInfo', $userMenu);
		}
		$this->assign ( "initRun", "getPublicLink();" );
		$this->display ( '/Link/index' );
	}
	
	function loadData() {
		if (cookie ( 'nwb_userid' ) != null) {
			$data = array (
					'email' => cookie ( 'nwb_email' ),
					'password' => cookie ( 'nwb_password' ) 
			);
			$redis = getObj ( 'redis' );
			$status = $redis->toLogin ( $data );
			if ($status == 1) {
				cookie ( 'nwb_email', cookie ( 'nwb_email' ), C ( "cookie_time" ) );
				cookie ( 'nwb_password', cookie ( 'nwb_password' ), C ( 'cookie_time' ) );
			}else {
				session ( 'nwb_islogin', null );
				session ( 'nwb_userid', 10000 );
				session ( 'nwb_email', 'visitor' );
			}
		}else {
				session ( 'nwb_islogin', null );
				session ( 'nwb_userid', 10000 );
				session ( 'nwb_email', 'visitor' );
		}
		
		if(session('nwb_userid') == ""){
			session ( 'nwb_islogin', null );
			session ( 'nwb_userid', 10000 );
			session ( 'nwb_email', 'visitor' );
		}
		
		session('nav_valiCode',rand(10000, 99999));
	}
	
	function inPrivateLink() {
		$this->assign ( "initRun", "getPrivateLink();" );
		$this->display ( '/Link/index' );
	}
	
	/* 验证码生成 */
	function doVerify() {
		$verify = new \Think\Verify ();
		$verify->fontSize = 30;
		$verify->length = 3;
		$verify->codeSet = '0123456789';
		$verify->imageL = 90;
		$verify->entry ();
	}
}